/**
 * 获取日期时间并传入指定格式
 */
export function getDateTime(date, format) {
  if (date) {
    date = new Date(date);
  } else {
    date = new Date();
  }
  if (!format) {
    format = "yyyy-MM-dd hh:mm:ss";
  }
  const o = {
    "M+": date.getMonth() + 1,
    "d+": date.getDate(),
    "h+": date.getHours(),
    "m+": date.getMinutes(),
    "s+": date.getSeconds(),
    "q+": Math.floor((date.getMonth() + 3) / 3),
    S: date.getMilliseconds()
  };
  if (/(y+)/.test(format)) {
    format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  }
  for (const k in o) {
    if (new RegExp("(" + k + ")").test(format)) {
      format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    }
  }
  return format;
}

/**
 * 获取当前时间是星期几
 */
export function getWeek(date) {
  if (date) {
    date = new Date(date);
  } else {
    date = new Date();
  }
  const week = date.getDay();
  return ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"][week];
}

/**
 * 获取当前时间是星期几 简化版本
 */
export function getWeekSimplify(date) {
  if (date) {
    date = new Date(date);
  } else {
    date = new Date();
  }
  const week = date.getDay();
  return ["周日", "周一", "周二", "周三", "周四", "周五", "周六"][week];
}
